﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;

namespace Log
{
    public class LogClass
    {
        public LogClass() { }

        public static void LogReader()
        {
            StreamReader objReader = new StreamReader(Config.Xml.LogConfigRead().LogPath);
            string sLine = "";
            ArrayList LineList = new ArrayList();
            while (sLine != null)
            {
                sLine = objReader.ReadLine();
                if (sLine != null && !sLine.Equals(""))
                    LineList.Add(sLine);
            }
            objReader.Close();
            
            //return LineList;
        }

        #region 写日志
        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="Content"></param>
        public static void LogWrite(string Content)
        {
            try
            {
                //差检测文件夹是否存在
                FileStream fs = new FileStream(Config.Xml.LogConfigRead().LogPath + @"\" + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString()+".log", FileMode.Append);
                StreamWriter sw = new StreamWriter(fs);
                //开始写入
                sw.Write("日期:" + 
                    DateTime.Now.Year.ToString() + "年" + 
                    DateTime.Now.Month.ToString() + "月" + 
                    DateTime.Now.Day.ToString() + "日" + 
                    DateTime.Now.Hour.ToString() + "时" +
                    DateTime.Now.Minute.ToString() + "分" + 
                    DateTime.Now.Second.ToString() + "秒     " + "消息:" + 
                    Content + 
                    System.Environment.NewLine);
                //清空缓冲区
                sw.Flush();
                //关闭流
                sw.Close();
                fs.Close();
            }
            catch
            {
                throw new Exception("写入日志错误!");
            }

        }


        #endregion
    }
}
